﻿
using Family.Core.Model;
using FluentNHibernate.Mapping;

namespace Family.Data.Mappings
{
    public class ProductMap : ClassMap<Product>
    {
        public ProductMap()
        {
            Id(p => p.Id).GeneratedBy.Native();
            Map(p => p.Name).Not.Nullable();

            References(p => p.Category, "CategoryId").Not.Nullable();

            HasMany(p => p.OrderItems)
                .KeyColumn("ProductId")
                .Cascade.AllDeleteOrphan()
                .Inverse();
        }
    }
}
